package auth

import (
	"context"
	"time"
	"xr-game-server/core/push"
	"xr-game-server/dao/accountdao"
	"xr-game-server/dao/roledao"
	"xr-game-server/dto/authdto"
)

func Ban(ctx context.Context, req *authdto.BanReq) (resp *authdto.BanRes, e error) {
	//默认永远封掉号
	db := accountdao.GetAccountById(req.AccountId)
	data := accountdao.GetAccountBy(db.OpenId, db.Channel)
	data.SetBan(true)
	data.SetUpdatedAt(time.Now())
	now := time.Now()
	data.SetBanTime(&now)
	data.SetBanApplyTime(req.BanApplyTime)
	//踢掉用户
	roles := roledao.GetRoleBy(req.AccountId)
	for _, role := range roles {
		push.Kick(role.ID)
	}

	return &authdto.BanRes{}, nil
}
func UnBan(ctx context.Context, req *authdto.UnBanReq) (bool, error) {
	db := accountdao.GetAccountById(req.AccountId)
	data := accountdao.GetAccountBy(db.OpenId, db.Channel)
	data.SetBan(false)
	data.SetBanTime(nil)
	data.SetBanApplyTime(nil)
	data.SetUpdatedAt(time.Now())
	return true, nil
}
